import { _decorator, animation, Animation, Collider2D, Component, Node, RigidBody2D } from 'cc';
import { StateDefine } from '../../Config';
import { IState } from '../../../fsm/State';
import { Player } from '../Player';


export abstract class PlayerState implements IState<StateDefine> {
    player: Player
    animation: Animation
    id: StateDefine;
    anim: string;
    rb: RigidBody2D | null = null;
    triggerCalled: boolean = false;
    stateTime: number = 0;
    // collider: Collider2D | null = null;
    constructor(name: StateDefine, player: Player, anim: StateDefine) {
        this.player = player;
        this.animation = player.animation;
        this.id = name;
        this.anim = anim;
        this.rb = this.player.rigidBody;
    }

    onEnter() {
        // console.info("Enter => "+this.anim);
        this.triggerCalled = false;
        this.animation.play(this.anim);

    }
    onExit() {
        this.player.BusyFor(20);
        // console.info("now onExit => "+this.id);
    }
    update(deltaTime: number) {
        this.stateTime -= deltaTime;
        // console.info(this.anim);
    }
    onDestory() { }

    canTransit(to: StateDefine): boolean {
        return true;
    }
    AnimationFinishTrigger(): void {
        this.triggerCalled = true;
    }
}


